//
//  JJAssetModel+internal.swift
//  JJAlbum
//
//  Created by 吴梓杭 on 2025/10/11.
//

import Photos

extension JJAssetModel {
    
    var internal_second: Int {
        guard type == .video else {
            return 0
        }
        return Int(round(asset.duration))
    }
    
    public func internal_init() {
        type = transformAssetType(for: asset)
        if type == .video {
            durationString = JJCommonTools.formatVideoDuration(asset.duration)
        }
    }
    
    private func transformAssetType(for asset: PHAsset) -> JJAssetModel.MediaType {
        switch asset.mediaType {
        case .video:
            return .video
        case .image:
            if asset.isGif {
                return .gif
            }
            if asset.mediaSubtypes.contains(.photoLive) {
                return .livePhoto
            }
            return .image
        default:
            return .unknown
        }
    }
    
}
